package com.example.libraryapp.network.base;


import com.example.libraryapp.network.net.ApiService;
import com.example.libraryapp.network.net.RetrofitManager;
import com.example.libraryapp.network.net.RxManager;
import com.example.libraryapp.network.net.RxSchedulers;

import io.reactivex.Observable;

/**
 * Presenter基类
 * @author 伍凯铭
 * @since 2020/2/27
 */
public abstract class BasePresenter<V extends IBaseView> {
    protected V mView;

    private RxManager rxManager;

    public BasePresenter() {
        rxManager = new RxManager();
    }

    protected <T> void doRequest(Observable<T> observable, IHttpListener<T> observerListener){
        rxManager.addObserver(RxSchedulers.doRequest(observable, observerListener));
    }

    protected ApiService getRequestService() {
        return RetrofitManager.getInstance().getRequestService();
    }

    public void attachView(V view) {
        this.mView = view;
    }

    public void detachView() {
        rxManager.clear();
        rxManager = null;
        mView = null;
    }

}
